<template>
  <div>
    <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
      <van-cell
        v-for="(item,index) in resultList"
        :key="index"
        :title="item.title"
        @click="$router.push('/articles/'+item.art_id)"
      />
    </van-list>
  </div>
</template>
           
<script>
import { getResults_api } from "@/api/search/index";
export default {
  props: ["searchValue"],
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      resultList: [],
      page: 1
    };
  },
  methods: {
    async onLoad() {
      //发送请求，获取result数据
      // console.log(this.searchValue,555);
      try {
        const { data: res } = await getResults_api({
          page: this.page,
          per_page: 10,
          q: this.searchValue
        });
        //  console.log(res.data.results,343434)
        this.resultList = res.data.results;
        // 加载状态结束
        this.loading = false;
        this.resultList = [...this.resultList, ...res.data.results];
        //判断长度，关闭下拉加载
        // 数据全部加载完成
        if (this.resultList.length) {
          this.page++;
        } else {
          this.finished = true;
        }
      } catch (err) {
        this.$toast("获取失败");
      }
    }
  }
};
</script>
<style scoped>
</style>